//
//  QPayPlayBoxView.m
//  QoilPublic
//
//  Created by 杨凯 on 16/8/23.
//  Copyright © 2016年 杨凯. All rights reserved.
//

#import "QPayPlayBoxView.h"
#import "QSetUpPassWordView.h"

static CGFloat w = 250;
static CGFloat h = 300;
@implementation QPayPlayBoxView{

    QSetUpPassWordView *textView;
    
    NSString *_passWorkStr;
    UILabel *threeSubLabel;
    
    UILabel *twoSubLabel;
}

- (instancetype)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];
    if(self){
    
        self.backgroundColor = [UIColor whiteColor];
        self.frame = CGRectMake((kScreenWidth-w)/2,(kScreenHeight-h)/2-20, w, h);
        self.layer.cornerRadius = 4.0;
        [self createUI];
    }
    return self;
}

- (void)createUI{

    __block QPayPlayBoxView *wSlef = self;
    
    UILabel *titleLabel = [QViewUtility createLabelWithFrame:CGRectMake(0,15, w, 18) font:Ksize16 textAlignment:NSTextAlignmentCenter textColor:[QColorUtility defaultBlueColor] text:@"输入密码"];
    [self addSubview:titleLabel];
    
    textView = [[QSetUpPassWordView alloc] initWithFrame:CGRectMake(15, titleLabel.bottom+15,w-30, 50)];
    textView.count = 4;
    textView.passwordBlock = ^(NSString *str){
        _passWorkStr = str;
        if(wSlef.StrBlock){
            wSlef.StrBlock(str);
        }
    };
    [self addSubview:textView];
    
    UIButton *forgetBtn = [QViewUtility createButtonWithFrame:CGRectMake((w-100)/2, textView.bottom+20, 100, 18) font:Ksize15 title:@"找回密码?" titleColor:[QColorUtility defaultBlueColor] backgroundColor:[UIColor clearColor]];
    forgetBtn.tag = 1;
    [forgetBtn addTarget:self action:@selector(payAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:forgetBtn];

    UILabel *oneLabel = [QViewUtility createLabelWithFrame:CGRectMake(15,forgetBtn.bottom+15,100,16) font:Ksize15 textAlignment:NSTextAlignmentLeft textColor:[QColorUtility defaultBackColor] text:@"付款方式"];
    [self addSubview:oneLabel];
    
    UILabel *oneSubLabel = [QViewUtility createLabelWithFrame:CGRectMake(w-110,forgetBtn.bottom+20,100,16) font:Ksize15 textAlignment:NSTextAlignmentRight textColor:[QColorUtility defaultDeepGrayColor] text:@"余额支付"];
    [self addSubview:oneSubLabel];
    
    
    UILabel *twoLabel = [QViewUtility createLabelWithFrame:CGRectMake(15,oneLabel.bottom+15,100,16) font:Ksize15 textAlignment:NSTextAlignmentLeft textColor:[QColorUtility defaultBackColor] text:@"账户余额"];
    [self addSubview:twoLabel];
    
    twoSubLabel = [QViewUtility createLabelWithFrame:CGRectMake(w-110,oneLabel.bottom+15,100,16) font:Ksize15 textAlignment:NSTextAlignmentRight textColor:[QColorUtility defaultDeepGrayColor] text:@""];
    [self addSubview:twoSubLabel];
    
    UILabel *threeLabel = [QViewUtility createLabelWithFrame:CGRectMake(15,twoSubLabel.bottom+15,100,16) font:Ksize15 textAlignment:NSTextAlignmentLeft textColor:[QColorUtility defaultBackColor] text:@"需付款"];
    [self addSubview:threeLabel];
    
    threeSubLabel = [QViewUtility createLabelWithFrame:CGRectMake(w-120,twoSubLabel.bottom+15,110,16) font:Ksize18 textAlignment:NSTextAlignmentRight textColor:[UIColor blackColor] text:@""];
    [self addSubview:threeSubLabel];
    
    
    UIButton *payButton = [QViewUtility createButtonWithFrame:CGRectMake(0, h-40, w, 40) font:Ksize16 title:@"确定付款" titleColor:[UIColor whiteColor] backgroundColor:[QColorUtility defaultBlueColor]];
    [payButton addTarget:self action:@selector(payAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:payButton];
    payButton.tag = 2;
    payButton.layer.cornerRadius = 2.0;
    [payButton blueStyle];
}

- (void)payAction:(UIButton *)btn{
    CLog(@"确定付款");
    [textView clearText];
    if(_NotiBlock){
        _NotiBlock(btn.tag);
    }
}

- (void)setPayMoneyStr:(NSString *)payMoneyStr{

    _payMoneyStr = payMoneyStr;
    threeSubLabel.text = [NSString stringWithFormat:@"%@元",_payMoneyStr];
}

- (void)setYuMoney:(NSString *)yuMoney{

    _yuMoney = yuMoney;
    twoSubLabel.text = [NSString stringWithFormat:@"%@元",_yuMoney];
}

@end
